package com.niiwoo.civet.trade.service.dubbo.lend;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.trade.dao.entity.LendOrderDetail;
import com.niiwoo.civet.trade.dao.entity.LendOrderDetailBiz;
import com.niiwoo.civet.trade.dao.mapper.LendOrderDetailBizMapperExt;
import com.niiwoo.civet.trade.dao.mapper.LendOrderDetailMapperExt;
import com.niiwoo.civet.trade.dto.common.LendOrderDetailBizDTO;
import com.niiwoo.civet.trade.dto.common.LendOrderDetailDTO;
import com.niiwoo.civet.trade.service.lend.ProjectLendDetailDubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * 放款明细处理
 * @author xiaoyaocai
 *
 */
@Service(version = "1.0.0")
public class ProjectLendDetailDubboServiceImpl implements ProjectLendDetailDubboService {

	@Autowired
	private LendOrderDetailMapperExt lendOrderDetailMapperExt ;
	@Autowired
	private LendOrderDetailBizMapperExt lendOrderDetailBizMapperExt;

	@Override
	public LendOrderDetailDTO queryLendOrderDetailByRequestNO(String requestNO) {
		LendOrderDetail lendOrderDetail = lendOrderDetailMapperExt.queryLendOrderDetailByDetailRequestNo(requestNO);
		LendOrderDetailDTO dto = new LendOrderDetailDTO();
		BeanUtils.copyProperties(lendOrderDetail,dto);
		return dto;
	}

	@Override
	public List<LendOrderDetailBizDTO> queryLeanOrderDetailByRequestNO(String requestNO, String bizType){
		List<LendOrderDetailBiz> lendOrderDetailBizs = lendOrderDetailBizMapperExt.queryLendOrderDetailBizByDetailRequestNoBizType(requestNO,(Byte.parseByte(bizType)));
		List<LendOrderDetailBizDTO> lendOrderDetailBizDTOS = new ArrayList<>();
		lendOrderDetailBizs.stream().forEach(vo ->{
			LendOrderDetailBizDTO lendOrderDetailBizDTO = new LendOrderDetailBizDTO();
			BeanUtils.copyProperties(vo,lendOrderDetailBizDTO);
			lendOrderDetailBizDTOS.add(lendOrderDetailBizDTO);
		});
		return lendOrderDetailBizDTOS;
	}

}
